<?php

include "parameters.lib";
include "databaseInteraction.lib";
include "ids.lib";
include "attributes.lib";
include "dataObjects.lib";

error_reporting(E_ALL);
ini_set('display_errors', '1');

try {
    
print("Insert id <br>"); 
$con = new Connection(serveur,log,mdp,base);
$newidobj = new Id();
$newidobj->save($con);
print($newidobj->getId());

print("<br>Insert dataobject<br>");

$newdataobj = new DataObject();
$newdataobj->setObjectId($newidobj->getId());
$newdataobj->setObjectType("test");
$newdataobj->setParent(0);
$newdataobj->setIsHisto(0);
$newdataobj->setDeleted(0);
$newdataobj->setOrderRank(1.15);

$newdataobj->save($con);
print("New id : ".$newdataobj->getUniqueId()."<br>");

print("<br>Get Dataobjects from id 1<br>");
$retrieveddataobjDataObject = getDataObjectFromObjectId(1,$con);
print(json_encode($retrieveddataobjDataObject));

print("<br>Insert dataobject with attributes<br>");

$newdataobj = new DataObject();
$newdataobj->setObjectId($newidobj->getId());
$newdataobj->setObjectType("testwithattributes");
$newdataobj->setParent(0);
$newdataobj->setIsHisto(0);
$newdataobj->setDeleted(0);
$newdataobj->setOrderRank(1.15);

$newAttribute = new Attribute();
$newAttribute->setName("att1");
$newAttribute->setDataType("string");
$newAttribute->setDataValue("value1");
$newdataobj->addAttribute($newAttribute);

$newAttribute = new Attribute();
$newAttribute->setName("att2");
$newAttribute->setDataType("string");
$newAttribute->setDataValue("value2");
$newdataobj->addAttribute($newAttribute);

$newAttribute = new Attribute();
$newAttribute->setName("att3");
$newAttribute->setDataType("int");
$newAttribute->setDataValue("12");
$newdataobj->addAttribute($newAttribute);

$newdataobj->save($con);
print("New id : ".$newdataobj->getUniqueId()."<br>");

print("<br>Get Dataobjects<br>");
$retrievedArray = getDataObjectsFromParent(0,$con);
print(json_encode($retrievedArray));

} catch (Exception $e) {
    print $e->getMessage();
    exit;
} 

?>
